<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>sessionstorage</title>
</head>


<body>
<button onclick="save()">save</button>
<button onclick="read()">read</button>
<button onclick="deleted()">delete</button>
<button onclick="cleanAll()">cleanAll</button>
</body>
<script type="text/javascript">
    //浏览器一关闭就没了
    let p ={name:'张三',age:13}
    function save(){
        window.sessionStorage.setItem('msg','hello!')
        window.sessionStorage.setItem('msg3',233)
        window.sessionStorage.setItem('msg4',JSON.stringify(p))
    }
    function read(){
        console.log(window.sessionStorage.getItem('msg'))
        console.log(JSON.parse(window.sessionStorage.getItem('msg4')) )
    }
    function deleted(){
        window.sessionStorage.removeItem('msg')
    }
    function cleanAll(){
        window.sessionStorage.clear()
    }
</script>
</html>
